package com.hxzy.drvier.api.fallback;

import com.hxzy.common.util.R;
import com.hxzy.drvier.api.DriverOpenFeignApi;
import com.hxzy.drvier.req.CreateDriverFaceModelReq;
import com.hxzy.drvier.req.UpdateDriverAuthReq;
import com.hxzy.drvier.resp.DriverResp;
import com.hxzy.drvier.req.RegisterNewDriverReq;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import feign.hystrix.FallbackFactory;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author wy
 * @Description 当feign调用失败的情况，我们需要如何来补救
 * @Date 2023/12/13 10:02
 * @Version 1.0
 */
@Log4j2
@Component
public class DriverOpenFeignFallbackFactory implements FallbackFactory<DriverOpenFeignApi> {

    @Override
    public DriverOpenFeignApi create(Throwable throwable) {
        log.error(throwable);
        return new DriverOpenFeignFallbackImpl();
    }

    /**
     * 内部类 (备用的类的实现)
     */
    static class DriverOpenFeignFallbackImpl implements DriverOpenFeignApi{


        @Override
        public R<DriverResp> getDriverInfo(long driverId) {
            return R.error(500,"feign服务调用getDriverInfo失败...");
        }

        @Override
        public R<Map<String, String>> registerNewDriver(RegisterNewDriverReq req) {
            return R.error(500,"feign服务调用registerNewDriver失败...");
        }

        @Override
        public R<Integer> updateDriverAuth(UpdateDriverAuthReq req) {
            return R.error(500,"feign服务调用updateDriverAuth失败...");
        }

        @Override
        public R<Map<String, String>> createDriverFaceModel(CreateDriverFaceModelReq req) {
            return R.error(500,"feign服务调用createDriverFaceModel失败...");
        }
    }

}
